#pragma once
#include <iostream>
#include <fstream> // 包含文件流头文件，用于文件操作
#include <vector>
using namespace std;

#include "Tire.h" //底盘包括轮胎类

// 底盘类
class Underpan
{
public:
    string id;         // 底盘编号 dp打头的8位数字+字母
    string model;      // 底盘型号SCOUT MINI
    int wheelbase;     // 轴距 451mm
    int track_width;   // 轮距 490mm
    int ground_clearance; // 最小离地间隙115mm
    int turning_radius;  // 最小转弯半径0m
    string drive_form; // 驱动形式
    int max_range;     // 最大行程
    vector<Tire> tires;  // 轮胎

    // 默认构造函数
    Underpan()
        : id("dp00000000"), model("SCOUT MINI"), wheelbase(451),
          track_width(490), ground_clearance(115), turning_radius(0),
          drive_form("四轮四驱"), max_range(10) {}

// 构造函数
    Underpan(string id, string model, int wheelbase, int track_width,
             int ground_clearance, int turning_radius,  string drive_form,
             int max_range,  vector<Tire> tires)
        : id(id), model(model), wheelbase(wheelbase), track_width(track_width),
          ground_clearance(ground_clearance), turning_radius(turning_radius),
          drive_form(drive_form), max_range(max_range), tires(tires) {}


    // 各属性的set方法
    void setID(string newID) {
        id = newID;
    }
    void setModel(string newModel) {
        model = newModel;
    }
    void setWheelbase(int newWheelbase) {
        wheelbase = newWheelbase;
    }
    void setTrackWidth(int newTrackWidth) {
        track_width = newTrackWidth;
    }
    void setGroundClearance(int newGroundClearance) {
        ground_clearance = newGroundClearance;
    }
    void setTurningRadius(int newTurningRadius) {
        turning_radius = newTurningRadius;
    }
    void setDriveForm(string newDriveForm) {
        drive_form = newDriveForm;
    }
    void setMaxRange(int newMaxRange) {
        max_range = newMaxRange;
    }
    void setTires(vector<Tire> newTires) {
        tires = newTires;
    }

    // 打印底盘信息
    void print() {
        cout << "底盘编号: " << id << endl;
        cout << "底盘型号: " << model << endl;
        cout << "轴距: " << wheelbase << "mm" << endl;
        cout << "轮距: " << track_width << "mm" << endl;
        cout << "最小离地间隙: " << ground_clearance << "mm" << endl;
        cout << "最小转弯半径: " << turning_radius << "m" << endl;
        cout << "驱动形式: " << drive_form << endl;
        cout << "最大行程: " << max_range << "KM" << endl;
        for (const auto &tire : tires) {
            cout << "轮胎型号: " << tire.type << ", 尺寸: " << tire.size << endl;
        }
        cout << "----------------------------------------" << endl;
    }

    // 保存底盘信息到本地文件
    void save(const string &filename) {
        ofstream outFile(filename, ios::app);  // 以追加模式打开文件
        if (!outFile.is_open()) {
            cerr << "无法打开文件 " << filename << endl;
            return;
        }
        outFile << "底盘编号: " << id << endl;
        outFile << "底盘型号: " << model << endl;
        outFile << "轴距: " << wheelbase << "mm" << endl;
        outFile << "轮距: " << track_width << "mm" << endl;
        outFile << "最小离地间隙: " << ground_clearance << "mm" << endl;
        outFile << "最小转弯半径: " << turning_radius << "m" << endl;
        outFile << "驱动形式: " << drive_form << endl;
        outFile << "最大行程: " << max_range << "KM" << endl;
        for (const auto &tire : tires) {
            outFile << "轮胎型号: " << tire.type << ", 尺寸: " << tire.size << endl;
        }
        outFile << "----------------------------------------" << endl;
        outFile.close();  // 关闭文件流
    }
};